//
//  DrawViewController.m
//  Leisure
//
//  Created by lanou on 16/6/28.
//  Copyright © 2016年 张凡. All rights reserved.
//

#import "DrawViewController.h"

@interface DrawViewController ()<MenuViewControllerDelegate>

@property(nonatomic,strong)MenuViewController *menuVC;//接收菜单栏
@property(nonatomic,strong)UINavigationController *rightNVC;//右侧视图导航控制器
@end

@implementation DrawViewController
//自定义初始化方法,在初始化的时候,就直接给上左右控制器
- (instancetype)initWithMenuViewController:(MenuViewController *)menuVC
                       RightViewController:(RightViewController *)rightVC
{
    self = [super init];
    if (self) {
       
        self.menuVC = menuVC;
        self.menuVC.delegate = self;
        self.rightNVC = [[UINavigationController alloc]initWithRootViewController:rightVC];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //添加子视图控制器
    [self addChildViewController:self.menuVC];
    [self addChildViewController:self.rightNVC];
    //添加子视图
    [self.view addSubview:self.menuVC.view];
    [self.view addSubview:self.rightNVC.view];
}
//实现协议方法,更换右视图
- (void)menuViewControllerDidClickCellWithVC:(RightViewController *)VC{

    
    [UIView animateWithDuration:0.2 animations:^{
        //替换之前先把旧的向右偏移
        self.rightNVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
    } completion:^(BOOL finished) {
        
        //先移除旧的
        [self.rightNVC removeFromParentViewController];
        [self.rightNVC.view removeFromSuperview];
        //再添加新的
        self.rightNVC = [[UINavigationController alloc]initWithRootViewController:VC];
        [self addChildViewController:self.rightNVC];
        [self.view addSubview:self.rightNVC.view];
        
        self.rightNVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
        //把新的再偏移回来
        [UIView animateWithDuration:0.2 delay:0.1 options:UIViewAnimationOptionLayoutSubviews animations:^{
           
            self.rightNVC.view.frame = self.view.frame;
        } completion:^(BOOL finished) {
            
        }];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
